/*
 * @Description: 
 * @Author: houcw
 * @Date: 2024-01-26 11:41:14
 * @LastEditTime: 2024-01-26 11:48:40
 * @LastEditors: houcw
 * @Reference: 
 */
const jwt = require('jsonwebtoken');
const config = require('../config/index')
// 'Lin_Server_token';
const singnKey = config.config 


// token 生成
function setToken(user_name){
    const token = jwt.sign(
        {name:user_name},
        singnKey,
        {expiresIn:"1h"}
    );
    return token
}

// 检验token

function verify_Token(token){
    return new Promise((resolve, reject) => {
        jwt.verify(token, singnKey, (err, decode) => {
            if (err) {
                return reject(err)
            } else {
                return resolve(decode)
            }
        })
    });
}

module.exports = {
    setToken,
    verify_Token
}